package zwp.example.demo1.demo_thread;

/**
 * 测试集合
 *
 * @author zwp14
 */
public class Demo {
    public static void main(String[] args) {
        //使用extends Thread创建线程
        MyThread myThread = new MyThread();
        myThread.start();

        //使用implements Runnable创建线程
        MyRunnable myRunnable = new MyRunnable();
        Thread thread = new Thread(myRunnable);
        thread.start();

        //使用匿名内部类创建线程
        new Thread(new MyRunnable(){
            @Override
            public void run() {
                super.run();
            }
        }).start();

        //使用匿名内部类创建线程
        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("使用匿名内部类创建线程------" + Thread.currentThread().getName());
            }
        });
        thread1.start();

        //使用lambda表达式创建线程
        Thread thread2 = new Thread(() -> {
            System.out.println("使用lambda表达式创建线程------" + Thread.currentThread().getName());
        });
        thread2.start();
    }
}
